//
//  YCBaseTabBarController.m
//  YCAdapterMode
//
//  Created by 安跃超 on 2018/12/14.
//  Copyright © 2018年 安跃超. All rights reserved.
//

#import "YCBaseTabBarController.h"
#import "YCMainModelAdapter.h"
#import "YCMainView.h"

@interface YCBaseTabBarController ()
@property (nonatomic, strong)NSArray<__kindof UIViewController *> *childViewControllers;
@property (nonatomic,strong)NSMutableArray<YCMainViewAdapter *> *dataSource;
@property (nonatomic,strong)YCMainView *mainView;
@end

@implementation YCBaseTabBarController

-(NSMutableArray<YCMainViewAdapter *> *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray arrayWithArray:[self getDataSource]];
    }
    return _dataSource;
}

-(NSMutableArray<YCMainViewAdapter *> *)getDataSource {
    return nil;
}

- (void)loadView {
    self.mainView = [[YCMainView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 44)];
    self.view = self.mainView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加子控制器
    [self setupChildViewControllers];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.mainView.dataArr = self.dataSource;
}

// 添加子控制器
- (void)setupChildViewControllers {
    self.hidesBottomBarWhenPushed = YES;
    [self setViewControllers:self.childViewControllers];
}


#pragma mark - getter method
- (NSArray<UIViewController *> *)childViewControllers {
    if (!_childViewControllers) {
//        YCBaseNavigationController *home = [YCBaseNavigationController baseViewController:[[YCHomeViewController alloc] init]];
//        DJBaseNavigationController *mine = [DJBaseNavigationController baseViewController:[[DJCenterViewController alloc] init]];
//        DJBaseNavigationController *rac = [DJBaseNavigationController baseViewController:[[DJReactiveCocoaViewController alloc] init]];

        NSMutableArray *vcArr = [[NSMutableArray alloc] initWithCapacity:6];
        for (YCMainModelAdapter *adapter in self.dataSource) {
            [vcArr addObject:[[adapter.destVC alloc] init]];
        }
        _childViewControllers = [NSArray arrayWithArray:vcArr];
    }
    return _childViewControllers;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}
@end
